#ifndef SDK_OHOS_OHOS_EXTERNAL_AUDIO_SOURCE_IMPL_
#define SDK_OHOS_OHOS_EXTERNAL_AUDIO_SOURCE_IMPL_

#include "api/audio/audio_mixer.h"
#include "api/audio/audio_frame.h"
#include "rtc_base/synchronization/mutex.h"
#include "common_audio/resampler/include/push_resampler.h"
#include <list>

namespace ohoswebrtc {
class OHOSExternalAudioSourceImpl : public webrtc::AudioMixer::Source {
public:
  OHOSExternalAudioSourceImpl();
  virtual ~OHOSExternalAudioSourceImpl();

  // implements ExternalAudioSource
  int DeliverFrame(unsigned char* pcm_data,
                  unsigned int nSamples,
                  unsigned int nBytesPerSample,
                  unsigned int nChannels,
                  unsigned int samplesPerSec,
                  unsigned short rec_delay_ms);

  // implments AudioMixer::Source interface
  webrtc::AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
      int sample_rate_hz,
      webrtc::AudioFrame* audio_frame) override;
  int Ssrc() const override;
  int PreferredSampleRate() const override;
  void Reset();

private:
  void ScaleAudioFrameList(std::list<std::shared_ptr<webrtc::AudioFrame>>& list, size_t scale);

private:
  mutable webrtc::Mutex mutex_;
  int32_t sample_rate_;
  std::list<std::shared_ptr<webrtc::AudioFrame>> write_list_;
  std::list<std::shared_ptr<webrtc::AudioFrame>> read_list_;
  webrtc::PushResampler<int16_t> deliver_resampler_;
  int ssrc_;
  bool insufficient_;
  size_t low_level_;
  size_t high_level_; 
  size_t max_level_;
  size_t no_data_count_;
  size_t frames_;

};

}

#endif


